home *** CD-ROM | disk | FTP | other *** search
/ Delphi Developer's Kit 1996 / Delphi Developer's Kit 1996.iso / power / freeres / readme.txt < prev    next >
Text File  |  1995-12-22  |  2KB  |  49 lines

  1. Freeing Windows Resources on the fly in Delphi
  2.  
  3.  
  4. Here is a fix for the out of resources problem many of us have 
  5. experienced when using Delphi to create a program with a large 
  6. number of controls (several hundred).
  7.  
  8. To illustrate the problem, I created a test program (RSTEST1) 
  9. with four forms.  Each form has a panel and one or two buttons.  
  10. Forms 2 and 3 also have a TTabSet and a TNotebook while form 4 
  11. has a TTabbedNotebook.  The notebooks and tabbed notebook  each 
  12. have 4 pages, one blank and the others with many controls.
  13.  
  14. If you run the program and cycle through all the forms and tabs 
  15. while running a resource monitoring program such as Dr. Bob's 
  16. RESMON available in the libraries, you will see a large 
  17. percentage of your resources being consumed.
  18.  
  19. I wrote a unit, FREERES.PAS which contains a procedure named 
  20. FreeResources which takes a TWinControl as its handle.  When 
  21. called, it causes the VCL to free the resources used by that 
  22. control and its descendants.  Note that if the controls were 
  23. visible they will disappear.  When you cause them to be shown 
  24. again, the resources will be reallocated by the VCL.
  25.  
  26. The second sample program, RESTEST2, has several examples of 
  27. using FreeResources on forms, notebook pages, and tabbed notebook 
  28. pages.  Form 3 frees the resources after another page or form has 
  29. been displayed, while the other forms do the reverse:  free the 
  30. resources of the visible page or form then show the new one.  
  31. This latter method causes more of a flicker on slow machines 
  32. while the former method temporarily consumes more resources.  
  33. Take your pick.
  34.  
  35. One thing you need to watch out for, it only works for controls 
  36. which never receive messages when they are not visible.  I guess 
  37. if someone used TWinControl or TCustomControl to derive a, for 
  38. example, Winsock component which does not really need to be 
  39. visible but needs a windows handle, you could run into problems.  
  40. I suggest testing it thoroughly in your application before 
  41. delivering it to paying customers!  Thanks to  Don Hatlestad for 
  42. pointing this out.
  43.  
  44. I hope this helps, and I welcome any feedback either through the 
  45. Delphi forum on Compuserve by E-mail:  Compuserve 76012,3614 or 
  46. Internet jseach@ix.netcom.com.
  47.  
  48. Jim Seach
  49.